<style type="text/css">
    h2.trigger {
        padding: 0 0 0 21px;
        margin: 0 0 5px 0;
        background: url(<?php echo $this->webroot; ?>img/tp.jpeg) no-repeat;
        /*	height: 46px;
                line-height: 46px;*/
        width: 450px;

        font-weight: normal;
        /*	float: left;*/
    }
    h2.trigger a {
        color: #000;
        text-decoration: none;
        display: block;
    }
    h2.trigger a:hover { color: #5e5e5e; }
    h2.active {background: url(<?php echo $this->webroot; ?>img/tm.jpeg) no-repeat;} /*--When toggle is triggered, it will shift the image to the bottom to show its "opened" state--*/
    .toggle_container {
        margin: 0 0 5px;
        padding: 0;
        border-top: 1px solid #d6d6d6;
        background: #f0f0f0  repeat-y left top;
        overflow: hidden;
        font-size: 1.2em;
        width: 500px;
        clear: both;
    }
    .toggle_container .block {
        padding: 20px; /*--Padding of Container--*/

    }
</style>    
<div id="result">
    <div class="div_header1" style=" font-size: 15px;">Negotiate (Make an Offer)</div>
    <form accept-charset="utf-8" action="<?php echo Configure::read('base_url'); ?>products/negotiate/" method="post" id="productmessage">
        <table cellspacing="0" >
            <tbody>    <tr>
                            <td ><span style="padding-right:50px;">To: &nbsp;&nbsp;&nbsp;<b>
                                        <?php echo $productinfo['User']['username']; ?></b></span><span style="padding-right:50px;">Item: &nbsp;&nbsp;&nbsp;<?php echo $productinfo['Product']['id']; ?>
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <td >Your Offer Price: $<?php
                            if($flag==2){
                            echo $this->Form->input('Negotiation.last_offer', array('label' => false, 'div' => false, 'class' => 'required number',
                                'value'=>$pendinginfo['Negotiation']['last_offer']));
                            }else{
                                echo $this->Form->input('Negotiation.last_offer', array('label' => false, 'div' => false, 'class' => 'required number'));
                            }
                            ?></td>
                        </tr>
                        <tr>
                            <td ></td>
                        </tr>
                        <tr>
                            <td >
                                <?php
                                        echo $this->Form->hidden('Negotiation.product_id', array('value' => $productinfo['Product']['id']));
                                        echo $this->Form->hidden('Negotiation.seller_id', array('value' => $productinfo['User']['id']));
                            if($flag==2){
                                echo $this->Form->hidden('Negotiation.id', array('value' => $pendinginfo['Negotiation']['id']));
                                        echo $this->Form->input('Negotiation.message', array('cols' => 70,'label'=>array('style'=>'vertical-align:top;'),'value'=>$pendinginfo['Negotiation']['message']));
                            }else{
                                        echo $this->Form->input('Negotiation.message', array('cols' => 70,'label'=>array('style'=>'vertical-align:top;')));
                            }
                                ?>
                                    </td>
                                </tr>
                                <tr>
                                    <td >
                                        <h2 class="trigger"><a href="#">View History</a></h2>
                                        <div class="toggle_container">
                                            <div class="block">
                                                <table cellspacing="0" width="100%">
                                                    <tbody>
                                        <tr>
                                            <td>
                                                Date
                                            </td>
                                            <td>
                                                Offered
                                            </td>
                                            <td>
                                                Status
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="3">
                                                <hr />
                                            </td>

                                        </tr>
                                        <?php if (!empty($history)) { ?>
                                            <?php foreach ($history as $historyvalue): ?>
                                                <tr>
                                                    <td>
                                                        <?php echo date('d-m-Y', strtotime($historyvalue['Negotiation']['created'])); ?>
                                                    </td>
                                                    <td>
                                                        <?php echo $historyvalue['Negotiation']['last_offer']; ?>
                                                    </td>
                                                    <td>
                                                        <?php echo $historyvalue['Negotiation']['status']; ?>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="3">
                                                        You wrote: <?php echo $historyvalue['Negotiation']['message']; ?> 
                                                    </td>

                                                </tr>
                                                <tr>
                                                    <td colspan="3">
                                                        Seller wrote: <?php echo $historyvalue['Negotiation']['seller_msg']; ?>
                                                    </td>

                                                </tr>
                                                <tr>
                                                    <td colspan="3">
                                                        <hr />
                                                    </td>

                                                </tr>
                                                <?php
                                            endforeach;
                                        }
                                        ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <input type="button" value="Close" name="" onclick="disablePopup()" size="10"
                               title="negotiate"   style="background:#73AE0B; color:#fff; font-size:14px;" />
                        &nbsp;&nbsp;
                        <input type="submit" style="background:#73AE0B; color:#fff; font-size:14px;" name="button" id="button" value="Negotiate" />
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</div>
<?php echo $html->script(array("jquery.min.js", "jquery.form.js", "jquery.validate.js")); ?>
<script type="text/javascript">
    jQuery(document).ready(function(){

        //Hide (Collapse) the toggle containers on load
        jQuery(".toggle_container").hide();

        //Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
        jQuery("h2.trigger").click(function(){
            jQuery(this).toggleClass("active").next().slideToggle("slow");
            return false; //Prevent the browser jump to the link anchor
        });

        // show a simple loading indicator
        var loader = jQuery('<div id="loader"><img src="<?php echo Configure::read('base_url'); ?>img/loading.gif" alt="loading..." /></div>')
        .css({position: "relative", top: "1em", left: "25em"})
        .appendTo("body")
        .hide();
        jQuery().ajaxStart(function() {
            loader.show();
        }).ajaxStop(function() {
            loader.hide();
        }).ajaxError(function(a, b, e) {
            throw e;
        });

        var v = jQuery("#productmessage").validate({
            rules: {
            },
            submitHandler: function(form) {
                jQuery(form).ajaxSubmit({
                    target: "#result"
                });
            }
        });
    });
</script>